﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SoccerEvaluator.Common;
using System.IO;
using SoccerEvaluator.Business;
using System.Web.UI.HtmlControls;
using System.Configuration;
using SoccerEvaluator.WebSite.App_Code;

namespace SoccerEvaluator.WebSite
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Match : System.Web.UI.Page
    {
        /// <summary>
        /// 
        /// </summary>
        protected int _groupID
        {
            get
            {
                if (Session["GroupId"] != null)
                {
                    return int.Parse(Session["GroupId"].ToString());
                }
                else return 0;
            }
        }
        /// <summary>
        ///
        /// </summary>
        protected int _projectID
        {
            get
            {
                if (Request.QueryString["ID"] != null)
                {
                    return int.Parse(Request.QueryString["ID"]);
                }
                else return 0;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (_projectID > 0)
            {
                Session["projectId"] = _projectID;

                RenderProject(_projectID);
            }
            else
            {
                Response.Redirect("GroupList.aspx");
            }


        }
        /// <summary>
        /// 
        /// </summary>
        private void RenderProject(int projectId)
        {
            SoccerEvaluatorModelContainer context = new SoccerEvaluatorModelContainer();

            Template t = context.Templates.FirstOrDefault(c => c.Id == projectId);

            TemplateInfo projectInfo = ObjectFactory.ToTemplateInfo(t);

            ScoreUpdater.UpdateProject(projectId, projectInfo.UrlScores, projectInfo.TableResults, projectInfo.StartDate, projectInfo.EndDate, projectInfo);

            this.txtMatchName.Text = projectInfo.Name;

            this.ImageLogo.Src = string.Format(@"~\Images\{0}", projectInfo.Logo);

            #region Carga informacion del proyecto
            this.lblExactScore.Text = projectInfo.ExactScore.ToString();
            this.lblCatchScore.Text = projectInfo.CatchScore.ToString();

            int totalRows = projectInfo.Scores.Count;            

            this.lstScores.DataSource = projectInfo.Scores;
            this.lstScores.DataBind();



            #endregion
        }        
      
    }
}